package com.activities;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.TourGuide.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.object.Map;

public class MyMapActivity extends MapActivity implements OnClickListener {
	MapView mapView = null;
	Map myMap = null;
	Button buttonChangeMode = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mymap);
		
		buttonChangeMode = (Button)findViewById(R.id.buttonChangeMode);
		buttonChangeMode.setOnClickListener(this);

		// Initialisation du manager GPS
		LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
		// Initialisation du manager des notifications
		NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		// Initialisation de la carte
		mapView = (MapView) findViewById(R.id.mapView);
		myMap = new Map(mapView, this, locationManager, notificationManager);
	}
	
	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		if (myMap.hasRoute())
			menu.add(0, 0, 0, "Voir les instructions");
		return true;
	}
	
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case 0:
				Intent myIntent = new Intent (this, InstructionsActivity.class);
				myIntent.putExtra("instructionsList", myMap.getDirectionsList());
				startActivity(myIntent);
				return true;
		}
		return super.onMenuItemSelected(featureId, item);
	}
	
	public void onClick(View v) {
		if(v.equals(buttonChangeMode)) {
			if (mapView.isSatellite())
				mapView.setSatellite(false); 
			else
				mapView.setSatellite(true);
		}
	}
}
